package com.yixun.qfbao.hander;

import com.yixun.qfbao.api.service.CPReportService;
import com.yixun.qfbao.api.service.ReceiveIntentionService;
import com.yixun.qfbao.apidto.ReceiveVisitReqDto;
import com.yixun.qfbao.apidto.ReceiveVisitResDto;
import com.yixun.qfbao.dto.base.BaseRequestDTO;
import com.yixun.qfbao.dto.base.BaseResponseDTO;
import com.yixun.qfbao.hander.base.CommonAbstractHander;
import com.yixun.qfbao.utils.TokenUtils;
import com.yixun.qfbao.vo.ReceiveVisitReqVo;
import com.yixun.qfbao.xf.model.enums.ResultEnum;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service("ReceiveVisitHander")
public class ReceiveVisitHander extends CommonAbstractHander {

    private Logger logger = LoggerFactory.getLogger(ReceiveVisitHander.class);

    @Autowired
    TokenUtils tokenUtils;
    @Autowired
    ReceiveIntentionService receiveIntentionService;
    @Override
    public BaseResponseDTO doBusiness(BaseRequestDTO reqDto) {
        BaseResponseDTO<ReceiveVisitResDto> res = new BaseResponseDTO<ReceiveVisitResDto>();
        ReceiveVisitResDto resDto = new ReceiveVisitResDto();
        ReceiveVisitReqVo reqVo = (ReceiveVisitReqVo)reqDto;
        ReceiveVisitReqDto receiveVisitReqDto = reqVo.getParams();
        resDto.setResult(ResultEnum.FAIL.getNo());
        try{
            resDto = receiveIntentionService.receiveVisit(receiveVisitReqDto);
            resDto.setResult(ResultEnum.SUCCESS.getNo());
        }catch (Exception e){
            logger.error("receive visit hander error: {}", e);
            res.setResult(ResultEnum.FAIL.getNo());
            res.setResult(e.getMessage());
        }
        res.setResult(resDto.getResult());
        res.setResData(resDto);
        return res;
    }
}
